package cn.pxs.dao;

import cn.pxs.entity.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TypeDao {
    @Autowired
    MongoTemplate mt;

    public List<Type> findAll(){
        List<Type> lst = mt.findAll(Type.class);
        return lst;
    }
    public Type findById(String id){
        Type t = mt.findById(id, Type.class);
        return t;
    }

    public Type add(Type t){
        Type t1 = mt.save(t);
        return t1;
    }

    public void delById(String id){
        mt.findAndRemove(new Query(Criteria.where("id").is(id)),Type.class);
    }


}
